package com.hanxy17.ssh.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import com.hanxy17.ssh.dao.IBDao;
import com.hanxy17.ssh.dao.base.BaseDao;
import com.hanxy17.ssh.domain.B;

//@Repository(value = "bDao") 
public class BDaoImpl extends BaseDao<B, Integer> implements IBDao {
	
	
	
//	 @Autowired
	private SessionFactory sessionFactory;
	
	
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}



	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}



	
	@Override
	public B getBByName(String name) {
		Session session = sessionFactory.getCurrentSession();
		List<B> list = new ArrayList<B>();
		// 通过Hibernate的Criteria查询
		Criteria criteria = session.createCriteria(B.class);
		if (!(null == name && "".equals(name))) {
			criteria.add(Restrictions.eq("name", name));
		}
		list = criteria.list();

		if (list != null && list.size() > 0) {
			System.out.println("from BDaoImpl.java.getBByName --return list");
			return list.get(0);
		}
		System.out.println("from BDaoImpl.java.getBByName --return null");
		return null;
	}

}
